package HomeWork;

import java.util.Random;

public class Role {
    private String name;
    private int blood;

    public Role() {
    }//空参

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    //定义一个方法用于攻击别人
    public void attack(Role role){
        Random r= new Random();
        int hurt =r.nextInt(20);//计算造成的伤害，1-20点

        int remainBlood=role.getBlood()-hurt;//计算攻击后剩余的血量

        remainBlood=remainBlood<0?0:remainBlood;//保证血量比0大
        role.setBlood(remainBlood);//人物的血量等于剩余的血量


        System.out.println(this.getName() + "举起拳头打了"+role.getName()+
                "一拳，造成了"+hurt+"点伤害,"+getName()+"还剩"+remainBlood+"血量");

    }

}
